package org.example.modules.user.service.Impl;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.example.common.utils.ThreadLocalUtil;
import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.UserFeedBack;
import org.example.modules.user.mapper.UserFeedBackMapper;
import org.example.modules.user.service.UserFeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @Description UserFeedBackServiceImpl
 * @Author xiaotian
 * @Date 2025-04-25
 */
@Slf4j
@Service
public class UserFeedBackServiceImpl extends ServiceImpl<UserFeedBackMapper, UserFeedBack> implements UserFeedBackService {

    @Autowired
    private UserFeedBackMapper userFeedBackMapper;

    @Override
    public void addFeedBack(JSONObject data) {
        UserFeedBack userFeedBack = data.toJavaObject(UserFeedBack.class);
        userFeedBack.setUserName(ThreadLocalUtil.getUserId());
        userFeedBack.setImages(data.getString("images"));
        userFeedBack.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        userFeedBack.setStatus("N");
        userFeedBackMapper.insert(userFeedBack);
    }

    @Override
    public Commsult<List<UserFeedBack>> getList() {
        return Commsult.success(userFeedBackMapper.getList());
    }
}
